<script type="text/javascript">
	/*function balanceCalc()
	{		if(parseFloat($("#newpayment").val()) > parseFloat($("#balance").val()))
			$("#newpayment").val(parseFloat($("#balance").val()));	
	}*/
</script>
<script language="JavaScript">
	function fncMinus()
	{
		 if(isNaN(document.form1.txtinputMoney.value) || document.form1.txtinputMoney.value == "")
		 {
			//alert('(Number B)Please input Number only.');
			document.form1.txtcashMoney.focus();
			return;
		 }
		 var inputMoney=parseFloat(document.form1.txtinputMoney.value);
		 var Balance=parseFloat(document.form1.txtBalance.value);
		 
		 if(inputMoney >= Balance){
			 document.form1.txtleftMoney.value = inputMoney - Balance;
			 document.form1.txtNewPay.value = Balance;
		 }else if(inputMoney < Balance){
			 document.form1.txtNewPay.value = inputMoney;
			 document.form1.txtleftMoney.value=0;
		 }
	}
</script>

<?php 
	include('function/connection.php');
	if(isset($_GET['billNumber'])){	
		$billNumber = $_GET['billNumber'];
		$query = "SELECT DISTINCT(sale_id),sale_date, amount, paid, balance, mode, cus_name, billnumber FROM tbl_sales WHERE  billnumber = '$billNumber'";
		$result = mysql_query($query);
      	$row = mysql_fetch_array($result);	
		$bill = $row['billnumber'];
		$date = $row['sale_date'];
		$amount = $row['amount'];
		$paid = $row['paid'];
		$balance = $row['balance'];
		$mode = $row['mode'];
		$cus_name = $row['cus_name'];
		$now = date('Y-m-d');
		$action = "oustanding";
	}
		
?>
<form action="verify_oustanding.php?action=<?php echo $action; ?>&bill=<?php echo $bill; ?>" class="form" name="form1" id="form1" method="post" enctype="multipart/form-data">
	<table class="bordered" width="770">
        <thead>
            <tr>
                <th>Add Sales Customer Payment:<br /><span class="red">* require feild</span></th>
            </tr>
        </thead>
	</table>
    <table class="bordered" width="770">
		<tr>
        	<td>
            	<label>Bill:</label>
            </td> 
			<td>
				<input type="text" class="txtPending" name="txtBill" value="<?php echo $bill; ?>" readonly="" /> 
            </td>           
		</tr>
        <tr>
        	<td>
        		<label>Date:</label>
            </td>
        	<td>
            	<input type="text" class="txtPending" name="txtDate" value="<?php echo $date; ?>" readonly="" /> 
            </td>
        </tr>
        <tr>
        	<td>
        		<label>Oustanding Date:</label>
            </td>
        	<td>
            	<input type="text" class="txtPending" name="txtOustDate" id="from_sales_date" value="<?php echo $now ?>" /> 
            </td>
        </tr>
        <tr>
       		<td>
            	<label>Customer:</label>
           	</td>
        	<td>
				<input type="text" class="txtPending" name="txtCustomer" value="<?php echo $cus_name; ?>" readonly="" />
           	</td>
		</tr>
        <tr>
        	<td>
            	<label>Amount:</label>
            </td>
			<td>
				<input type="text" class="txtPending" name="txtAmount" value="<?php echo $amount; ?>" readonly="" />
            </td>
        <tr>
       		<td>
            	<label>Paid:</label>
            </td>
            <td>
            	<input type="text" class="txtPending" name="txtPaid" value="<?php echo $paid; ?>" readonly="" />
            </td>
		</tr>
        <tr>
       		<td>
            	<label>Balance:</label>
            </td>
            <td>
            	<input class="txtPending" name="txtBalance" type="text" id="balance" value="<?php echo $balance; ?>" readonly="" />
            </td>
		</tr>
        <tr>
       		<td>
            	<label>Mode:</label>
            </td>
            <td>
            	<input type="text" class="txtPending" name="txtMode" value="<?php echo $mode; ?>" readonly="" />
            </td>
		</tr>
        <tr>
       		<td>
            	<label><span class="red">*</span>New Payment:</label>
            </td>
            <td>
            	<input name="txtinputMoney" class="input req-min" minlength="1" type="text" id="txtinputMoney" value=""   onKeyUp="fncMinus();" style="width:233px; height:25px;" />
                
            </td>
            <td><input name="txtNewPay" type="hidden" id="newpayment" value=""  /></td>
           
            	
		</tr>
        <tr>
       		<td>
            	<label><span class="red">*</span>Left Money:</label>
            </td>
            <td>
            	<input name="txtleftMoney" class="input req-min" minlength="1" type="text" id="txtleftMoney" value="" readonly="readonly" style="width:233px; height:25px;"/>
            </td>
		</tr>
		<tr>
			<td colspan="4"><input type="submit" class="btnSubmit" id="Submit" name="payNow" value="Pay Now" />&nbsp; 
            <input type="button" class="btnSubmit" name="btnSubmit" value="Cancel" onclick="redirect('index.php?page=oustanding_list&action=oustanding_list')" /></td>
		</tr>
	</table>
</form>